package com.xiaodai.miaosha.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaodai.miaosha.entity.Msuser;
import com.xiaodai.miaosha.entity.Screening;
import com.xiaodai.miaosha.mapper.ScreeningMapper;
import com.xiaodai.miaosha.service.IScreeningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaodai
 * @since 2022-04-12
 */
@Service
public class ScreeningServiceImpl extends ServiceImpl<ScreeningMapper, Screening> implements IScreeningService {
    @Resource
    private ScreeningMapper screeningMapper;
    @Override
    public void doScreening(Msuser msuser) {

        Boolean flag;
        Screening screening = screeningMapper.selectOne(new QueryWrapper<Screening>().eq("msuser_id", msuser.getId()));
        flag = msuser.getOverdueRecords() <= 2 && msuser.getInDefaultList() != 1 && msuser.getWorkStatus() != 1 && msuser.getWorkStatus() != 2 && msuser.getAge() >= 18;

        if (screening==null){
            screening = new Screening();
            screening.setPassed(flag?1:0);
            screening.setMsuserId(String.valueOf(msuser.getId()));
            screeningMapper.insert(screening);
        }
        screening.setPassed(flag?1:0);
        screeningMapper.updateById(screening);
    }
}
